package dex.studio.compose.news.ui.data

import dex.studio.compose.news.ui.data.bean.DataBean
import dex.studio.compose.news.ui.data.bean.NewsBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import rxhttp.map
import rxhttp.toClass
import rxhttp.wrapper.param.RxHttp

object Repository {
    fun getInstance(): Repository {
        return this
    }

    suspend fun getNewsList(): List<NewsBean> {
        var res = mutableListOf<NewsBean>()
        withContext(Dispatchers.IO)
        {
            res = RxHttp.postJson("https://api.apiopen.top/getWangYiNews")
                .toClass<DataBean>()
                .map {
                    it.result
                }
                .await()
        }
        return res
    }
}